# Различные пути
SHARED_SRC=../sysshare/src
SHARED_BIN=../sysshare/bin
SRC=src
BIN=bin
GRAPH_DIR=$(BIN)/sys/fsm/graph

SMC_PATH=$(SHARED_BIN)/smc_5_1/Smc.jar
STATEMAP_LIB_PATH=$(SHARED_BIN)/smc_5_1/statemap.jar
JAVA_MAIL_PATHS=$(SHARED_BIN)/javamail-1.4.2/mail.jar:$(SHARED_BIN)/javamail-1.4.2/lib/smtp.jar:$(SHARED_BIN)/javamail-1.4.2/lib/pop3.jar:$(SHARED_BIN)/javamail-1.4.2/lib/mailapi.jar:$(SHARED_BIN)/javamail-1.4.2/lib/mail.jar
MYSQL_CONNECTOR_PATH=$(SHARED_BIN)/mysql-connector/mysql-connector-java-5.1.7-bin.jar

FSM_SRC=$(SRC)/sys/fsm
SMC_SRC=$(SRC)/sys/smc

# Ява компилятор и его параметры
JAVAC = javac
JAVAC_PARAMS = -classpath $(SRC):$(STATEMAP_LIB_PATH):$(JAVA_MAIL_PATHS):$(JSON_PATH):$(MYSQL_CONNECTOR_PATH) -d $(BIN)

# Виртуальная машина Ява и её параметры
JAVA=java
JAVA_PARAMS=-classpath .:../$(STATEMAP_LIB_PATH):../$(JAVA_MAIL_PATHS):../$(JSON_PATH):../$(MYSQL_CONNECTOR_PATH)

all: compileSMC compileJAVA

# Генерация кода из общего кода и из кода отдельной системы
$(BIN)/sys/timer/%.class: $(SHARED_SRC)/sys/timer/%.java 
	cp $< $(SRC)/sys/timer/ && $(JAVAC) $(JAVAC_PARAMS) $<

$(BIN)/sys/logic/%.class: $(SHARED_SRC)/sys/logic/%.java 
	cp $< $(SRC)/sys/logic/ && $(JAVAC) $(JAVAC_PARAMS) $<

$(BIN)/sys/transport/%.class: $(SHARED_SRC)/sys/transport/%.java 
	cp $< $(SRC)/sys/transport/ && $(JAVAC) $(JAVAC_PARAMS) $<

$(BIN)/sys/message/%.class: $(SHARED_SRC)/sys/message/%.java 
	cp $< $(SRC)/sys/message/ && $(JAVAC) $(JAVAC_PARAMS) $<

$(BIN)/sys/database/DBWrapper.class: $(SHARED_SRC)/sys/database/DBWrapper.java
	cp $< $(SRC)/sys/database/ && $(JAVAC) $(JAVAC_PARAMS) $<

$(BIN)/sys/utils/%.class: $(SHARED_SRC)/sys/utils/%.java 
	cp $< $(SRC)/sys/utils/ && $(JAVAC) $(JAVAC_PARAMS) $<

$(BIN)/%.class: $(SRC)/%.java 
	$(JAVAC) $(JAVAC_PARAMS) $<

# Все файлы, описывающие конечные автоматы в формате SMC
compileSMC: $(addprefix $(FSM_SRC)/, AutomatContext.java)

# Все java-файлы
compileJAVA: $(addprefix $(BIN)/sys/utils/, ReadWriteTextFile.class) $(addprefix $(BIN)/sys/timer/,TimerClient.class Timer.class)  $(addprefix $(BIN)/sys/message/, UniMessage.class JSONMessage.class) $(addprefix $(BIN)/sys/transport/,MessageReceiver.class MessageSender.class MessageReceiverPOP3.class MessageSenderSMTP.class) $(addprefix $(BIN)/sys/database/, DBWrapper.class SyscDatabase.class) $(addprefix $(BIN)/sys/logic/,MessageCheckerClient.class MessageChecker.class ) $(addprefix $(BIN)/sys/fsm/, Automat.class AutomatContext.class) $(addprefix $(BIN)/sys/, Main.class RequestManager.class) 
#$(addprefix $(BIN)/sys/tests/logic/, Test1.class Test2.class RunTests.class)

run: all
	cd $(BIN) && $(JAVA) $(JAVA_PARAMS) sys.Main 

runLogicTests: all
	cd $(BIN) && $(JAVA) $(JAVA_PARAMS) sys.Main "LogicTests"
